package com.four.bmm.util;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Properties;

/**
 * 会用的用,分页
 * @param <T>
 */
public class Pagnation<T> implements Serializable {
    private int pageNo;
    private int totalPages;
    private int totalRows;
    private int prevPage;
    private List<T> list;
    private int nextPage;
    public static int pageSize;
    static{
        Properties properties=new Properties();
        try {
            properties.load(Pagnation.class.getResourceAsStream("/config.properties"));
            pageSize=Integer.parseInt(properties.getProperty("pageSize"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
        if(totalRows%pageSize==0){
            totalPages=totalRows/pageSize;
        }else{
            totalPages=totalRows/pageSize+1;
        }
        if(pageNo-1<=0){
            prevPage=1;
        }else{
            prevPage=pageNo-1;
        }
        if(pageNo+1>=totalPages){
            nextPage=totalPages;
        }else{
            nextPage=pageNo+1;
        }
    }

    public int getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
}

